
if exists (select 1 from sysobjects where name = 'get_abteilungen' and type = 'P')
begin
   drop procedure get_abteilungen
   print 'Procedure: get_abteilungen deleted ...'
end
go
create procedure get_abteilungen(
  @mandid          char(2)           = 'li',
  @abteilungid     int               = 0
)
as
begin
  set nocount on
         
  select abteilungid = AbteilungID,
         name = a.Name,
         beschreibung = b.Langtext,
         einsatzprotag = stundenprotag
    from Abteilung a
   inner join Beschreibung b 
      on b.BeschrID = a.BeschrID
   where (mandid = @mandid or @mandid = '')
     and (AbteilungID = @abteilungid or @abteilungid = 0)
   order by AbteilungID

end
go
print 'Procedure: get_abteilungen done ...'
go
grant exec on get_abteilungen to prsadmins with grant option
go
grant exec on get_abteilungen to prsusers
go

